//
//  TypeCell.swift
//  Bee
//
//  Created by kyson on 15/12/31.
//  Copyright © 2015年 kyson. All rights reserved.
//

import UIKit

class TypeCell: CPCollectionViewCell {
    
    private var innerIsSelected:Bool = false
    
    var innerCellTitle:String = ""

    @IBOutlet private weak var contentButton: UIButton!
    
    typealias CellClickCallBack = ()->()
    
    var cellClickCallBack : CellClickCallBack?

    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    func setButton(name name: String){
        contentButton.setTitle(name, forState: UIControlState.Normal)
    }
    
    var isButtonSelected :Bool{
        get{
            return innerIsSelected
        }
        
        set(selected){
            innerIsSelected = selected
            
            if(true == innerIsSelected){
                contentButton.setTitleColor(UIColor.greenColor(), forState: UIControlState.Normal)
            }else{
                contentButton.setTitleColor(UIColor.grayColor(), forState: UIControlState.Normal)
            }
        }
    }
    
    var cellTitle :String{
        get{
            return innerCellTitle
        }
        
        set(cellTitle){
            innerCellTitle = cellTitle
            contentButton.setTitle(innerCellTitle, forState: UIControlState.Normal)
        }
    }
    
    @IBAction func buttonClicked(sender: UIButton) {
        if(nil != cellClickCallBack){
            self.innerIsSelected = true
            print("-------:" + self.innerIsSelected.description)
            
            cellClickCallBack!()
        }
    }

}
